package com.oraro.paygatewaybiz.aspect;

import com.oraro.paygatewaybiz.exception.RRException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: jianghuiyong
 * @Date: 2018/12/4 17:24
 * @Version 1.0
 */
@Aspect
@Configuration
@Slf4j
public class RedisAspect {

    @Value("${spring.redis.open: false}")
    private boolean open;

    @Around("execution(* com.oraro.paygatewaybiz.utils.RedisUtil.*(..))")
    public Object around (ProceedingJoinPoint point){
        Object result = null;
        if (open) {
            try {
                result = point.proceed();
            } catch (Throwable throwable) {
                log.error(throwable.toString());
                throw new RRException("redis 服务异常");
            }
        }
        return result;
    }

}
